package com.schoolegard.services.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.schoolegard.services.HdTypeService;
import com.schoolgard.dao.HdTypeDao;
import com.schoolgard.entitybean.HdType;

public class HdTypeServiceImpl implements HdTypeService {
	
	private HdTypeDao hdTypeDao;

	public void saveOrUpdate(HdType hdType) {
		hdTypeDao.createOrModify(hdType);
	}

	public void deleteType(Long id) {
		if(id == null || id == 0) {
			return;
		}
		HdType hdType = hdTypeDao.findById(id);
		hdTypeDao.remove(hdType);
	}

	public List<HdType> queryTypeAll() {
		DetachedCriteria criteria = DetachedCriteria.forClass(HdType.class);
		criteria.add(Restrictions.eq("enable",true));
		return hdTypeDao.findByCriteria(criteria);
	}

	public HdType queryTypeById (Long id){
		if(id == null) {
			return null;
		}
		return hdTypeDao.findById(id);
	}
	
	public void setHdTypeDao(HdTypeDao hdTypeDao) {
		this.hdTypeDao = hdTypeDao;
	}

}
